﻿using System;
using System.Windows.Data;
using System.Globalization;
using System.Collections.Generic;


namespace FRL.DebtChased.ChaseWorkspace
{
    public class DateTimeToYearConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime date = (DateTime)value;
            return date.ToShortDateString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string strValue = value.ToString();
            DateTime resultDateTime;
            if (DateTime.TryParse(strValue, out resultDateTime))
            {
                return resultDateTime;
            }
            return value;
        }
    }


    public class InvoiceStatusToTextConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string status;
            CachedData.Singleton.InvoiceStatuses.TryGetValue(System.Convert.ToInt32(value), out status);
            return status;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            foreach (KeyValuePair<int, string> kvp in CachedData.Singleton.InvoiceStatuses)
            {
                if (kvp.Value == (string)value)
                    return kvp.Key;
            }
            return 0;
        }
    }
}
